<?php
// 获得所有医生信息
// header("content-type:text/html;charset=UTF-8");
include_once("conn.php");

$select = "SELECT * FROM doc_infos JOIN department_infos ON doc_infos.doc_TypeMain = department_infos.department_ID";
$tips = "当前共有";

if (isset($_GET["secrch_doc_id"])) {
    $secrch_doc_id = $_GET["secrch_doc_id"];
    $select = "SELECT * FROM doc_infos JOIN department_infos ON doc_infos.doc_TypeMain = department_infos.department_ID WHERE doc_infos.doc_ID LIKE '%" . $secrch_doc_id . "%'";
    $tips = "通过医生ID：“" . $secrch_doc_id . "”，查询到";
}

if (isset($_GET["secrch_doc_name"])) {
    $secrch_doc_name = $_GET["secrch_doc_name"];
    $select = "SELECT * FROM doc_infos JOIN department_infos ON doc_infos.doc_TypeMain = department_infos.department_ID WHERE doc_infos.doc_Name LIKE '%" . $secrch_doc_name . "%'";
    $tips = "通过医生姓名：“" . $secrch_doc_name . "”，查询到";
}

if (isset($_GET["secrch_doc_department"])) {
    $secrch_doc_department = $_GET["secrch_doc_department"];
    $select = "SELECT * FROM doc_infos JOIN department_infos ON doc_infos.doc_TypeMain = department_infos.department_ID WHERE doc_infos.doc_TypeMain = '" . $secrch_doc_department . "'";
    $tips = "该科室共有";
}

$result = mysqli_query($connect_DB, $select);
if ($result) {
    if (mysqli_num_rows($result) > 0) {
        echo "
        <p class='s-info'>" . $tips . mysqli_num_rows($result) . "位医生信息</p>
            <div class='table-div'>
                <table class='table table-striped'>
                    <thead>
                        <tr>
                            <th scope='col'>工号ID</th>
                            <th scope='col'>姓名</th>
                            <th scope='col'>所属科室</th>
                            <th scope='col'>接诊状态</th>
                            <th scope='col'>联系电话</th>
                            <th scope='col'>操作</th>
                        </tr>
                    </thead>
                    <tbody>";
        while ($row = mysqli_fetch_object($result)) {
            if ($row->doc_Accept == 1) {
                $status = "正常在诊";
            } else {
                $status = "暂停接诊";
            }
            echo "
            <tr>
                <th scope='row'>" . $row->doc_ID . "</th>
                <td>" . $row->doc_Name . "</td>
                <td>" . $row->department_Name . "</td>
                <td>" . $status . "</td>
                <td>" . $row->doc_Phone . "</td>
                <td><a href='admin_DoctorInfoPage.php?docID=" . $row->doc_ID . "'>详情</a> / <a href='a_DelDoctorInfo.php?docID=" . $row->doc_ID . "' onclick='return delConfirm();'>删除</a></td>
            </tr>
            ";
        }
        echo "</tbody> </table> </div>";
    } else {
        echo "<p class='s-info'>" . $tips . "0位医生信息</p>";
    }

} else {
    echo "<p class='s-info'>查询出错：" . $select . "</p>";
}

$connect_DB->close();
?>